home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / New System Software Extensions / ASLM SDK v1.1.2 / ASLM Examples / Inspector / Sources / RegisteredObjectsWindow.cp < prev    next >
Encoding:
Text File  |  1994-11-21  |  7.2 KB  |  250 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RegisteredObjectsWindow.cp
  3.  
  4.     Contains:    Implementation of TRegisteredObjectsWindow.  A window that displays a list
  5.                 of TRegisteredObjects.
  6.  
  7.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  8.  
  9. */
  10.  
  11. #ifndef __WINDOWS__
  12. #include <Windows.h>
  13. #endif
  14. #ifndef __LIST__
  15. #include <List.h>
  16. #endif
  17. #ifndef __EVENTS__
  18. #include <Events.h>
  19. #endif
  20. #ifndef __TOOLUTILS__
  21. #include <ToolUtils.h>
  22. #endif
  23. #ifndef __FONTS__
  24. #include <Fonts.h>
  25. #endif
  26.  
  27. #ifndef __REGISTEREDOBJECTSWINDOW__
  28. #include <RegisteredObjectsWindow.h>
  29. #endif
  30. #ifndef __REGISTEREDOBJECTS__
  31. #include <RegisteredObjects.h>
  32. #endif
  33. #ifndef __STRING__
  34. #include <string.h>
  35. #endif
  36.  
  37. /**********************************************************************
  38. **  PUBLIC Constructor/Destructor
  39. ***********************************************************************/
  40.  
  41. TRegisteredObjectsWindow::TRegisteredObjectsWindow()
  42. {
  43.     fList                = NULL;
  44.     fRegisteredObjects    = NULL;
  45. }
  46.  
  47. TRegisteredObjectsWindow::TRegisteredObjectsWindow(short resID,
  48.     TRegisteredObjects *theObjects) : TDocument(resID)
  49. {
  50.     InitRegisteredObjectsWindow(theObjects);
  51. }
  52.  
  53. TRegisteredObjectsWindow::~TRegisteredObjectsWindow()
  54. {
  55.     //Trace("Disposing TRegisteredObjectsWindow\n");
  56.     fRegisteredObjects->SetRegisteredObjectsWindow(NULL);    /* we no longer exist */
  57.     HideWindow(fDocWindow);
  58.     delete fList;
  59. }
  60.  
  61. /**********************************************************************
  62. ** PRIVATE InitRegisteredObjectsWindow
  63. ***********************************************************************/
  64.  
  65. void TRegisteredObjectsWindow::InitRegisteredObjectsWindow(TRegisteredObjects *theObjects)
  66. {
  67.     GrafPtr savedPort;
  68.     GetPort(&savedPort);
  69.     SetPort(fDocWindow);
  70.     TextFont(monaco);
  71.  
  72.     /* set the windows title */
  73.  
  74.     char theName[256];
  75.     strcpy(&theName[1],theObjects->GetClassName());
  76.     theName[0] = strlen(&theName[1]);
  77.     SetWTitle(GetDocWindow(),StringPtr(theName));
  78.  
  79.     /* setup the List Manager list */
  80.  
  81.     Rect listRect = fDocWindow->portRect;
  82.     listRect.right -= 15;            // scroll bar space
  83.     listRect.bottom -= 15;            // scroll bar space
  84.     listRect.left += kButtonSpace;    // button space
  85.     Rect dataBounds = {0,0,0,1};        // empty 1 column list
  86.     Point cSize = {0,0};                // let list manager decide cell size
  87.     fList = new TList(&listRect,&dataBounds,cSize,0,fDocWindow,
  88.                 true/*drawit*/, true/*hasgrow*/, false/*hScroll*/, true/*vScroll*/);
  89.     fList->SetSelFlags(lOnlyOne);        // only allow one cell to be selected
  90.     (**fList->GetList()).cellSize.h = 16383;
  91.     
  92.     fRegisteredObjects = theObjects;
  93.     theObjects->SetRegisteredObjectsWindow(this);    /* it needs a pointer to us */
  94.     UpdateList();
  95.  
  96.     SetPort(savedPort);
  97. }
  98.  
  99. /**********************************************************************
  100. ** PUBLIC DoContent
  101. ***********************************************************************/
  102.  
  103. void TRegisteredObjectsWindow::DoContent(EventRecord* theEvent)
  104. {
  105.     //Trace("TRegisteredObjectsWindow::DoContent\n");
  106.     Point mouse;
  107.  
  108.     SetPort(fDocWindow);
  109.     mouse = theEvent->where;                // get the click position 
  110.     GlobalToLocal(&mouse);
  111.     Rect listRect = GetListRect();
  112.     listRect.right += 15;                    // 15 for the scrollbars
  113.     listRect.bottom += 15;                    // 15 for the scrollbars
  114.     if (PtInRect(mouse,&listRect)) {        // did we click in list regions?
  115.         if (fList->Click(mouse,theEvent->modifiers)) {    // did we double click?
  116.             Cell theCell = fList->LastClick();            // what cell did we double click in
  117.             //*fRegisteredObjects[theCell.v]->Dump();    // dump the object
  118.             TDynamic* theObj = (*fRegisteredObjects)[theCell.v]; 
  119.             //delete theObj;
  120.         }
  121.     }
  122. }
  123.  
  124. /**********************************************************************
  125. ** PUBLIC DoGrow
  126. ***********************************************************************/
  127.  
  128. void TRegisteredObjectsWindow::DoGrow(EventRecord* theEvent)
  129. {
  130.     Rect sizeRect = {100,175, 32767, 32767};
  131.     Rect oldRect = fDocWindow->portRect;
  132.     long result = GrowWindow(fDocWindow, theEvent->where, &sizeRect);
  133.     if (result) {
  134.         short h = LoWord(result);
  135.         short v = HiWord(result);
  136.         SizeWindow(fDocWindow, h, v, true);
  137.         fList->DoDraw(false);
  138.         fList->Size(h - 15 - kButtonSpace, v - 15);
  139.         fList->DoDraw(true);
  140.         DrawWindow();
  141.     }
  142. }
  143.  
  144. /**********************************************************************
  145. ** PUBLIC DoActivate
  146. ***********************************************************************/
  147.  
  148. void TRegisteredObjectsWindow::DoActivate(Boolean becomingActive)
  149. {
  150.     DrawGrowIcon();
  151.     fList->Activate(becomingActive);
  152. }
  153.  
  154. /**********************************************************************
  155. ** PUBLIC DoUpdate
  156. ***********************************************************************/
  157.  
  158. void TRegisteredObjectsWindow::DoUpdate()
  159. {
  160.     BeginUpdate(fDocWindow);                // this sets up the visRgn 
  161.     if (!EmptyRgn(fDocWindow->visRgn)) {    // draw if updating needs to be done 
  162.         fList->Update(fDocWindow->visRgn);
  163.     }
  164.     DrawGrowIcon();
  165.     MoveTo(fDocWindow->portRect.left + kButtonSpace - 1, fDocWindow->portRect.top);
  166.     LineTo(fDocWindow->portRect.left + kButtonSpace - 1, fDocWindow->portRect.bottom);
  167.     EndUpdate(fDocWindow);
  168. }
  169.  
  170. /**********************************************************************
  171. ** PUBLIC DrawWindow
  172. ***********************************************************************/
  173.  
  174. // Draw the contents of an application window. 
  175.  
  176. void TRegisteredObjectsWindow::DrawWindow()
  177. {
  178.     Rect tRect;
  179.  
  180.     SetPort(fDocWindow);
  181.     tRect = fDocWindow->portRect;
  182.     EraseRect(&tRect);
  183.     InvalRect(&tRect);
  184. }
  185.  
  186. /**********************************************************************
  187. ** PUBLIC UpdateList
  188. ***********************************************************************/
  189.  
  190. void TRegisteredObjectsWindow::UpdateList()
  191. {
  192.     GrafPtr savedPort;
  193.     GetPort(&savedPort);
  194.     SetPort(GrafPtr(GetDocWindow()));
  195.  
  196.     EraseRect(&(**fList->GetList()).rView);
  197.  
  198.     fList->DoDraw(false);        // turn off list drawing
  199.     fList->DelRow(0,0);            // delete the entire list
  200.     unsigned long count = fRegisteredObjects->GetCount();
  201.     fList->AddRow(short(count));    // make space for the cells
  202.     for (int row = 0; row<count; row++) {
  203.         fRegisteredObjects->GetSemaphore()->Grab();    // don't let list change on us
  204.         if (fRegisteredObjects->GetCount() > row) {    // make sure list has index "row"
  205.             char theData[256];
  206.             (*fRegisteredObjects)[row]->GetVerboseName(theData);    // get the text for the new cell
  207.             fRegisteredObjects->GetSemaphore()->Release();    // ok, it can change now
  208.             
  209.             Cell cell = {0,0};                // {row,0} won't work!!!
  210.             cell.v = row;                    // we'll add the cell to the end
  211.             fList->SetCell(theData,strlen(theData),cell);
  212.         }
  213.         else
  214.             fRegisteredObjects->GetSemaphore()->Release();
  215.     }
  216.  
  217.     // force the list to be updated
  218.  
  219.     fList->DoDraw(true);        // turn on list drawing
  220.     InvalRect(&(**fList->GetList()).rView);
  221.     SetPort(savedPort);
  222. }
  223.  
  224. /**********************************************************************
  225. ** PUBLIC GetListRect
  226. ***********************************************************************/
  227.  
  228. Rect TRegisteredObjectsWindow::GetListRect()
  229. {
  230.     return fList->GetListRect();
  231. }
  232.  
  233.  
  234. /**********************************************************************
  235. ** PUBLIC DrawGrowIcon
  236. ***********************************************************************/
  237.  
  238. void TRegisteredObjectsWindow::DrawGrowIcon()
  239. {
  240.     ::DrawGrowIcon(fDocWindow);
  241.     
  242.     /* get rid of extra "grow icon" section in lower left corner */
  243.     Rect r = fDocWindow->portRect;
  244.     r.top = r.bottom - 16;
  245.     r.bottom -=14;
  246.     r.right = r.left + kButtonSpace - 1;
  247.     EraseRect(&r);
  248. }
  249.  
  250.